#!/bin/sh

if ! which cargo >/dev/null 2>&1; then
	echo "Error: cargo not found." >&2
	exit 1
fi

for pkg in $(cargo install --list | grep '^[^[:space:]]' | awk '{print $1}'); do
	printf '\nUpdating %s\n' "$pkg"

	if [ "$pkg" = "atdf2svd" -o \
	     "$pkg" = "svd2rust" -o \
	     "$pkg" = "svdtools" ]; then
		echo "Skipped."
		continue
	fi

	locked=
	if [ "$pkg" = "bacon" -o \
	     "$pkg" = "cargo-vet" ]; then
		locked="--locked"
	fi

	cargo install $locked "$@" "$pkg" || exit 1
done

exit 0
